<template>
    <div id=form>
            <span>用户名</span>
            <input v-model="name"  placeholder="请输入用户名" required autofocus><br>
            <span>密码</span>
            <input v-model="pwd" type="password"  placeholder="请输入密码" required><br>
            <button @click="login()" >登录</button><br>
            <img class="ftimg" src="../assets/登录.png" alt="">
    </div>
</template>
<style src="../style/init.css" scoped>

</style>
<script>
export default {
    data:function(){
        return{
            name:"",
            pwd:"",
        }
    },
    methods:{
        login:function(){
            var user={name:this.name,pwd:this.pwd}
            this.$store.commit('queryuser',user)
            var mess=this.$store.state.mess
            if(mess=='f'){
                alert("用户不存在")
                return
            }
            else if(this.pwd==mess){
                sessionStorage.username=this.name
                alert("欢迎━(*｀∀´*)ノ亻!")
                this.$router.replace("/");//避免后退

            }else{
                alert("用户名或密码错误")
            }
        },
    },
}
</script>